package lin.an.food.controller;

import lin.an.food.entity.FoodReview;
import lin.an.food.service.FoodReviewService;
import lin.an.pojo.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhoulinq
 * @date 2025/4/12
 */
@RestController
@RequestMapping("/delicious/food/review")
public class FoodReviewController {

    @Autowired
    private FoodReviewService foodReviewService;

    @GetMapping("/list")
    public CommonResult<List<FoodReview>> getReviews(@RequestParam int foodId) {
        return CommonResult.data(foodReviewService.getReviewsByFoodId(foodId));
    }

    @PostMapping("/add")
    public CommonResult<String> addReview(@RequestBody FoodReview review) {
        foodReviewService.addReview(review);
        return CommonResult.ok();
    }

    @DeleteMapping("/delete")
    public CommonResult<String> deleteReview(@RequestParam int reviewId, @RequestParam int userId) {
        foodReviewService.deleteReview(reviewId, userId);
        return CommonResult.ok();
    }
}